//
//  LJJGoodsListCollectionView.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/21.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJGoodsListCollectionView.h" 
#import "LJJGoodsListCollectionViewCell.h"

@interface LJJGoodsListCollectionView ()<UICollectionViewDelegate, UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation LJJGoodsListCollectionView
static NSString *identifier = @"goodsListCollectionCell";

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        [self registerClass:[LJJGoodsListCollectionViewCell class] forCellWithReuseIdentifier:identifier];
    }
    return self;
}
- (void)setGoodsListArray:(NSArray *)goodsListArray
{
    _goodsListArray = goodsListArray;
}
#pragma mark -
#pragma mark - UICollectionView delegate & dataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.goodsListArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LJJGoodsListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    cell.goodsListModel = self.goodsListArray[indexPath.row];

    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    LJJGoodsListModel *model = self.goodsListArray[indexPath.row];
    NSString *goodsID = model.GoodsId;
    if (_selectCollectionBlock) {
        _selectCollectionBlock(goodsID);
    }
}

@end
